package com.leanyuan.publi.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leanyuan.publi.domain.House;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.leanyuan.publi.dto.Statisticsto;
import com.leanyuan.publi.dyno.HouseProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 相亲相爱一家人
 * @since 2021-05-25
 */
public interface HouseMapper extends BaseMapper<House> {
    @Results(id="base",value = {
            @Result(property = "building.name",column = "lname"),
            @Result(property = "userinfo.username",column = "username")
    })
    @Select({"<script> " +"select h.*,b.`name` as'lname',u.username " +
        "from house h left join building b " +
        "on h.building_id=b.building_id left join userinfo u on h.user_id=u.user_id where 1=1 and housecondition='0'" +
            "<if test='id!=null'> and h.name=#{id}</if>"+
            "<if test='lname!=null'> and b.name=#{lname}</if>"+
            "<if test='username!=null'> and u.username like '%${username}%'</if>"+
        "</script>"})
    List<House> findAll(Page<House> page, @Param("id") Integer id,@Param("lname") String lane,@Param("username") String yezhuname);

    @Results(id="base2",value = {
            @Result(property = "building.name",column = "lname"),
            @Result(property = "userinfo.username",column = "username")
    })
    @Select({"<script> " +"select h.*,b.`name` as'lname',u.username " +
            "from house h left join building b " +
            "on h.building_id=b.building_id left join userinfo u on h.user_id=u.user_id where 1=1" +
            "<if test='id!=null'> and h.name=#{id}</if>"+
            "<if test='lname!=null'> and b.name=#{lname}</if>"+
            "<if test='username!=null'> and u.username like '%${username}%'</if>"+
            "and h.user_id is null"+
            "</script>"})
    List<House> findAll2(Page<House> page, @Param("id") Integer id,@Param("lname") String lane,@Param("username") String yezhuname);

    @UpdateProvider(type = com.leanyuan.publi.dyno.HouseDynaSqlProvider.class,method = "updateHouseSql")
     int upd(House house);

    @InsertProvider(type = com.leanyuan.publi.dyno.HouseDynaSqlProvider.class,method ="insertHouseSql")
    int ins(House house);

    @UpdateProvider(type = com.leanyuan.publi.dyno.HouseDynaSqlProvider.class,method = "update2HouseSql")
    int upd2(House house);

    @SelectProvider(type = HouseProvider.class,method = "selectCount")
    public List<Statisticsto> findCount();
}
